{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch import nn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 4])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = torch.tensor([[1, 1, 1, 1], [2, 3, 3, 4]])\n",
    "a.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "ebd = nn.Embedding(5, 24)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[ 2.5605, -1.9209, -0.2103,  0.0945, -1.0939,  2.6814,  0.8553,\n",
       "           2.3072, -0.6347, -1.2694,  0.0758,  0.2138,  0.5953, -1.8128,\n",
       "           0.3511, -0.3355,  0.2789, -0.2591, -1.0050, -0.8811,  1.6111,\n",
       "           0.9723, -0.3956, -0.0641],\n",
       "         [ 2.5605, -1.9209, -0.2103,  0.0945, -1.0939,  2.6814,  0.8553,\n",
       "           2.3072, -0.6347, -1.2694,  0.0758,  0.2138,  0.5953, -1.8128,\n",
       "           0.3511, -0.3355,  0.2789, -0.2591, -1.0050, -0.8811,  1.6111,\n",
       "           0.9723, -0.3956, -0.0641],\n",
       "         [ 2.5605, -1.9209, -0.2103,  0.0945, -1.0939,  2.6814,  0.8553,\n",
       "           2.3072, -0.6347, -1.2694,  0.0758,  0.2138,  0.5953, -1.8128,\n",
       "           0.3511, -0.3355,  0.2789, -0.2591, -1.0050, -0.8811,  1.6111,\n",
       "           0.9723, -0.3956, -0.0641],\n",
       "         [ 2.5605, -1.9209, -0.2103,  0.0945, -1.0939,  2.6814,  0.8553,\n",
       "           2.3072, -0.6347, -1.2694,  0.0758,  0.2138,  0.5953, -1.8128,\n",
       "           0.3511, -0.3355,  0.2789, -0.2591, -1.0050, -0.8811,  1.6111,\n",
       "           0.9723, -0.3956, -0.0641]],\n",
       "\n",
       "        [[ 0.9716, -0.2768, -0.6439, -0.0654, -0.6727, -0.6430, -0.6372,\n",
       "          -1.0042,  0.1499, -0.6780,  0.8793,  0.6833,  0.5106,  0.4822,\n",
       "          -0.1824,  0.4725, -0.4958,  1.9042,  0.0154, -0.3216, -1.6836,\n",
       "          -0.5288, -0.6054, -0.8657],\n",
       "         [ 1.0994, -1.0231,  0.3265,  0.1720, -2.5360,  1.5921,  0.4752,\n",
       "           0.5682, -0.8918,  0.0534,  0.2685,  0.3885,  1.1401, -1.1854,\n",
       "           0.9652,  0.2465,  1.0205,  1.1573,  0.3956, -1.0821, -0.6115,\n",
       "          -0.5387,  0.0896, -1.5415],\n",
       "         [ 1.0994, -1.0231,  0.3265,  0.1720, -2.5360,  1.5921,  0.4752,\n",
       "           0.5682, -0.8918,  0.0534,  0.2685,  0.3885,  1.1401, -1.1854,\n",
       "           0.9652,  0.2465,  1.0205,  1.1573,  0.3956, -1.0821, -0.6115,\n",
       "          -0.5387,  0.0896, -1.5415],\n",
       "         [-1.0119,  0.4683,  0.6215,  0.5590,  0.2337,  0.6817, -0.2057,\n",
       "           1.0883,  0.9612, -1.2651, -0.2175, -1.9384,  0.9750,  0.8071,\n",
       "           0.2240,  1.3059,  0.4221, -1.2727,  1.4663,  0.8813, -0.3493,\n",
       "           0.0466, -1.1597, -1.8829]]], grad_fn=<EmbeddingBackward0>)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bbb = ebd(a)\n",
    "bbb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 4])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 4, 24])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bbb.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 4])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = torch.tensor([[1, 1, 1, 1], [2, 3, 3, 4]])\n",
    "a.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([1, 4])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos = torch.tensor([[0, 1, 2, 3]])\n",
    "pos.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 4, 24])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word_ebd = ebd(a)\n",
    "word_ebd.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([1, 4, 24])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ebd2 = nn.Embedding(4, 24)\n",
    "pos_ebd = ebd2(pos)\n",
    "pos_ebd.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "custom_trans",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
